package com.piggy.common.log.service;

import com.piggy.common.core.utils.SpringUtils;
import com.piggy.common.core.utils.ip.AddressUtils;
import com.piggy.logi.sys.api.domain.LogiSysOperLog;
import com.piggy.sys.api.domain.SysOperLog;
import lombok.extern.slf4j.Slf4j;

import java.util.TimerTask;

/**
 * 异步工厂（产生任务用）
 *
 * @author ruoyi
 */
@Slf4j
public class AsyncFactory {

    /**
     * 操作日志记录
     *
     * @param operLog 操作日志信息
     * @return 任务task
     */
    public static TimerTask saveSysLog(final SysOperLog operLog) {
        return new TimerTask() {
            @Override
            public void run() {
                // 远程查询操作地点
                //operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp()));
                SpringUtils.getBean(AsyncLogService.class).saveSysLog(operLog);
            }
        };
    }

    /**
     * 操作日志记录
     *
     * @param operLog 操作日志信息
     * @return 任务task
     */
    public static TimerTask saveLogiSysLog(final LogiSysOperLog operLog) {
        return new TimerTask() {
            @Override
            public void run() {
                // 远程查询操作地点
                //operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp()));
                SpringUtils.getBean(AsyncLogService.class).saveSysLogiLog(operLog);
            }
        };
    }
}
